//
//  ReDetailViewController.m
//  海角音乐
//
//  Created by dllo on 15/8/6.
//  Copyright (c) 2015年 杨元石. All rights reserved.
//

#import "ReDetailViewController.h"

@interface ReDetailViewController ()

@end

@implementation ReDetailViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    
    CGFloat title_width = SCREEN_WIDTH*0.533333; // 200
    CGFloat title_height = SCREEN_WIDTH*0.08; // 30
    self.TitleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, title_width, title_height)];
    self.TitleView.textColor = [UIColor whiteColor];
    self.TitleView.textAlignment = NSTextAlignmentCenter;
    self.TitleView.text = self.recommedModel.desc;
    self.navigationItem.titleView = self.TitleView;
    
    
    
//    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    
    _picArr = [[NSMutableArray alloc] init];
    _ChinaVc = [[ChinaViewController alloc] init];
    _EuropeVc = [[EuropeViewController alloc] init];
    _JanpanVc = [[JanpanViewController alloc] init];
    
    _ChinaVc.recommedModel = self.recommedModel;
    _EuropeVc.recommedModel = self.recommedModel;
    _JanpanVc.recommedModel = self.recommedModel;    
    
    [self addChildViewController:_ChinaVc];
    [self addChildViewController:_EuropeVc];
    [self addChildViewController:_JanpanVc];
    
    
    

//    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    
    _srollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _srollView.delegate = self;
    _srollView.pagingEnabled = YES;
    _srollView.contentSize = CGSizeMake(SCREEN_WIDTH*3, 0);
    [self.view addSubview:_srollView];
    
    
    _ChinaVc.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    _EuropeVc.view.frame = CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    _JanpanVc.view.frame = CGRectMake(SCREEN_WIDTH*2, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    
    [_srollView addSubview:_ChinaVc.view];
    [_srollView addSubview:_EuropeVc.view];
    [_srollView addSubview:_JanpanVc.view];
    
    
    
    NSArray *titleArr = @[@"华语", @"欧美", @"日韩"];
    CGFloat width = SCREEN_WIDTH*0.6666666; // 250
    CGFloat width_height = SCREEN_WIDTH*0.08; // 30
    
    _segmentControl = [[UISegmentedControl alloc] initWithItems:titleArr];
    _segmentControl.frame = CGRectMake(0, 0, width, width_height);
    [_segmentControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    _segmentControl.backgroundColor = [UIColor colorWithRed:32/255 green:36/255 blue:50/255 alpha:1];
    _segmentControl.tintColor = [UIColor colorWithRed:66/255.0 green:149/255. blue:245/255.0 alpha:1.0];
    _segmentControl.selectedSegmentIndex = 0;
    self.navigationItem.titleView = _segmentControl;
    [_segmentControl release];
    

    DanLiPlayer *dan = [DanLiPlayer shareHandleDanLiPlayer:CGRectZero];
    [self.view addSubview:dan];
    
    
}





// 滑动
- (void)segmentAction:(UISegmentedControl *)segment
{
    
    if (segment.selectedSegmentIndex == 0) {
        
        [_srollView setContentOffset:CGPointMake(0, 0)];
        
    } else if (segment.selectedSegmentIndex == 1) {
        
        [_srollView setContentOffset:CGPointMake(SCREEN_WIDTH, 0)];
        
    } else if (segment.selectedSegmentIndex == 2) {
        
        [_srollView setContentOffset:CGPointMake(SCREEN_WIDTH*2, 0)];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (_srollView.contentOffset.x == 0) {
        
        _segmentControl.selectedSegmentIndex = 0;
        
    } else if (_srollView.contentOffset.x == SCREEN_WIDTH) {
        
        _segmentControl.selectedSegmentIndex = 1;
        
    } else if (_srollView.contentOffset.x == SCREEN_WIDTH*2) {
        
        _segmentControl.selectedSegmentIndex = 2;
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
